const app = getApp();
Page({
  data: {
    countdown:'',    
    endDate2: '2020-09-18 10:40:00'
    },
  onLoad:function(e){
    var that = this;
    that.countTime()
  },
  countTime() {
    var that = this;
    var date = new Date();
    var now = date.getTime();
    var endDate = new Date(that.data.endDate2);//设置截止时间
    console.log(endDate)
    var end = endDate.getTime();
    console.log(end)
    var leftTime = end - now; //时间差 
    console.log(leftTime)                             
    var d, h, m, s, ms;
    if (leftTime >= 0) {
      d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
      h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
      m = Math.floor(leftTime / 1000 / 60 % 60);
      s = Math.floor(leftTime / 1000 % 60);
      ms = Math.floor((leftTime % 1000) / 10);
      ms = ms < 10 ? "0" + ms : ms
      s = s < 10 ? "0" + s : s
      m = m < 10 ? "0" + m : m
      h = h < 10 ? "0" + h : h
      that.setData({
        countdown: d + ":" + h + ":" + m + ":" + s + ":" + ms,
      })
     //递归每秒调用countTime方法，显示动态时间效果
    setTimeout(that.countTime, 100);
    } else {
      console.log('已截止')
      that.setData({
        countdown:'00:00:00'
      })
    }
  }
})